
<template>

  <!-- <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
    <el-menu >
      <button style="width:100%;height:30px;margin-top:60px;border-radius:5px">addtodox</button>
      <button @click="jump" style="width:100%;height:30px;margin-top:60px;border-radius:5px">list</button>
    </el-menu>
  </el-aside> -->
  <div style="font-family:SimSun">
    <header style="height:60px;background:red; width:100%;display:block">123</header>
    <div style="width:100%;background:green;margin-top:10px">
      <div style="width:50%;float:left;">
          <h2><span style="text-align:center;display:block;" >山村咏怀</span></h2>
          <div style="text-align:center;margin-top:10px">
            <p>邵雍</p>

            <p>一去二三里,</p>
            <p> 烟村四五家。</p>
            <p>亭台六七座,</p>
            <p>八九十枝花。</p>
          </div>
          
      </div>
       <div style="width:50%;float:left;">
          <h2><span style="text-align:center;display:block">name</span></h2>
      </div>
    </div>
  </div>
 
   

</template>

<style>
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    line-height: 60px;
  }
  
  .el-aside {
    color: #333;
  }
</style>

<script>
import {config} from '../util'
import Mkdown from './Mkdown'
import axios from 'axios'
import fetchJsonp from 'fetch-jsonp';
import leftside from './layout/leftside'

  export default {
    components: {
     Mkdown,
    leftside
    },
    data() {
      const item = {
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      };
      return {
        content:'',
        form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        value1: '',
        value2: '',
        value3: '',
        input:'title',
        pickerOptions1: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        },
        tableData: Array(20).fill(item)
      }
    },
    methods: {
       jump:function(){
        this.$router.push('/list');
      },
      alert() {
        this.$message('这是一条消息提示');
      },
      success() {
        this.$message({
          message: '恭喜你，这是一条成功消息',
          type: 'success'
        });
      },

      warn(msg) {
        this.$message({
          message: msg,
          type: 'warning'
        });
      },

      open4() {
        this.$message.error('错了哦，这是一条错误消息');
      },
     
      onSubmit() {
        var $this=this
        if(this.value1==''){
          this.warn('please input your start time ')
          return
        }
        if(this.value2==''){
          this.warn('please input your end time ')
          return
        }
        console.log(123)
        var starttime=this.value1.getTime()/1000
        var endtime=this.value2.getTime()/1000
        var title=this.form.name
        var istrue=this.form.delivery
        var language=this.form.type
        var tag=''
        for(var i=0;i<language.length;i++){
          var tag=tag+language[i]+','
        }
        tag=tag.slice(0,tag.length-1)

        console.log(language)
        var level=this.form.level
        var content=this.content
        var url=config.baseurl
        var requerturl=url+'/api/addtodo'
       
        var useTime=endtime -starttime
        if (useTime<=0){
          this.open3('input false time')
        }
        var data={
          startTime:starttime,
          endTime:endtime,
          title:title,
          note:content,
          level:level,
          useTime:useTime,
          tag:tag
        }
        console.log(data)
        var msg=function(obj){
          var url=''
          Object.keys(obj).forEach(function(key){
            // var value=obj[key].
            // value=value.replace('+','%2B')
            url+='&'+key+'='+obj[key]
          })
          url=url.slice(1,url.length)
          console.log(url)
          return url
        }
        var params = msg(data);
        requerturl=requerturl+'?'+params
        $this.fullscreenLoading = true;

        fetchJsonp(requerturl)
        .then(function(response) {
          return response.json()
        }).then(function(json) {
          $this.$router.push('/edittodo?id='+json);
        }).catch(function(ex) {
          console.log('parsing failed', ex)
          $this.fullscreenLoading = false;

        })

        
      }
    }
  };
</script>
<style>
.block{
  margin:15px;
}

</style>


           